package com.clz.appdesign.Notification;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.clz.appdesign.myapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ProgressBarActivity extends AppCompatActivity {

    @BindView(R.id.progressBar_total)
    ProgressBar mProgressBarTotal;
    @BindView(R.id.progressBar_child)
    ProgressBar mProgressBarChild;
    @BindView(R.id.tv_ammount)
    TextView mTvAmmount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification2);
        ButterKnife.bind(this);
        initProgressbar();
    }

    private void initProgressbar() {

        mProgressBarTotal.post(() -> {
            final int totalWidth = mProgressBarTotal.getWidth();
            final ViewGroup.LayoutParams layoutParams = mProgressBarChild.getLayoutParams();
            layoutParams.width = (int) (totalWidth * 0.86);
            mProgressBarChild.setLayoutParams(layoutParams);
            ObjectAnimator objectAnimator = ObjectAnimator.ofInt(mProgressBarChild, "progress", 0, 100);
            objectAnimator.setDuration(3000);
            objectAnimator.setInterpolator(new LinearInterpolator());
            objectAnimator.start();
            objectAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mTvAmmount.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);
                    mTvAmmount.setVisibility(View.GONE);
                }
            });
        });
    }
}
